using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
namespace DesignCrystalReport
{
    public partial class frmReport : Form
    {
        ReportDocument rptDoc = null;
        public frmReport()
        {
            InitializeComponent();
        }

        private void frmReport_Load(object sender, EventArgs e)
        {
            // truy van csdl de lay du lieu ve
            string strSQL = "select od.CustomerID, od.OrderID, od.OrderDate, "+
                "odt.ProductID, pr.ProductName, odt.UnitPrice, odt.Quantity, "+
                "odt.UnitPrice*odt.Quantity as Amount from Orders od inner join "+
                "[Order Details] as odt on od.OrderID = odt.OrderID inner join "+
                "Products pr on pr.ProductID = odt.ProductID";

            SqlConnection conn = new SqlConnection("server=(local); database=Northwind; uid=sa; pwd=;");
            SqlDataAdapter adapter = new SqlDataAdapter(strSQL, conn);

            DataSet ds = new DataSet();
            adapter.Fill(ds, "OrderInfo");

            // load file CrystalReport
            string path = Application.StartupPath;
            path += @"\rptOrderInfo.rpt";
            rptDoc = new ReportDocument();
            rptDoc.Load(path, OpenReportMethod.OpenReportByTempCopy);

            // Gan Data source cho Crystal Report
            rptDoc.SetDataSource(ds.Tables["OrderInfo"]);
            
            // Gan doi tuong ReportDocument rptDoc chgo thuoc tinh ReportSource cua 
            // dieu khien CrystalReportViewer
            crystalReportViewer1.ReportSource = rptDoc;


        }
    }
}